//初始化
var form;
var $;
var laydate;
var table;
layui.use(['form','laydate','jquery','table'],function(){
    form = layui.form;
    $ = layui.$;
    laydate=layui.laydate;
    table=layui.table;

    var idArray = window.location.search.split("?");
    var userId = idArray[1];

    //下拉菜单
    form.on('select(collection)', function(data){
        if(data.value==2){
            $.ajax({
                url:"/personnel/selCollectionCourse",
                type:"post",
                dataType:"json",
                data:{"userId":userId,"type":2},
                success:function(item) {
                    courseTable(item.data);
                }
            });
        }else if(data.value==3){
            $.ajax({
                url:"/personnel/selCollectionProduct",
                type:"post",
                dataType:"json",
                data:{"userId":userId,"type":3},
                success:function(item) {
                    productTable(item.data);
                }
            });
        }else if(data.value==4){
            $.ajax({
                url:"/personnel/selCollectionForum",
                type:"post",
                dataType:"json",
                data:{"userId":userId,"type":4},
                success:function(item) {
                    forumTable(item.data);
                }
            });
        }
    });

    fun();
    function fun() {
        var idArray = window.location.search.split("?");
        var userId = idArray[1];

        $.ajax({
            url:"/personnel/selCollectionCourse",
            type:"post",
            dataType:"json",
            data:{"userId":userId,"type":2},
            success:function(item) {
                courseTable(item.data);
            }
        });
    }

    //课程
    function courseTable(data) {
        table.render({
            elem:"#table_id",
            data:data,
            limit:6,
            toolbar:'#toolbarDemo',
            page:true,
            cols:[[
                {type:'checkbox',align:'center',width:40},
                {title:'序号',width:60,align:'center',templet:function(data){
                        return data.LAY_INDEX;
                    }},
                {field:'url',title:'课程图片',align:'center',width:130,templet:function(data){
                        return "<img src='"+data.url+"'height='100'>"
                    }},
                {field:'course_name',title:'课程名称',align:'center'},
                {field:'course_nprice',title:'价格',align:'center',templet:function(data){
                        return "$"+data.course_nprice+"";
                    }},
                {field:'name',title:'分类',align:'center'},
                {field:'collect_num',title:'收藏量',align:'center'},
                {field:'like_num',title:'点赞量',align:'center'},
                {field:'sale_num',title:'销量',align:'center'}
            ]]
        });
    }

    //商品
    function productTable(data) {
        table.render({
            elem:"#table_id",
            data:data,
            limit:6,
            toolbar:'#toolbarDemo',
            page:true,
            cols:[[
                {type:'checkbox',align:'center',width:40},
                {title:'序号',width:60,align:'center',templet:function(data){
                        return data.LAY_INDEX;
                    }},
                {field:'main_image',title:'商品图片',align:'center',width:130,templet:function(data){
                        return "<img src='"+data.main_image+"'height='100'>";
                    }},
                {field:'product_name',title:'商品名称',align:'center'},
                {field:'currentprice_product',title:'价格',align:'center',templet:function(data){
                        return "$"+data.currentprice_product+"";
                    }},
                {field:'categroy_name',title:'分类',align:'center'},
                {field:'collection_volume',title:'收藏量',align:'center'},
                {field:'fabulous',title:'点赞量',align:'center'},
                {field:'product_label',title:'销量',align:'center'}
            ]]
        });
    }

    //微圈
    function forumTable(data) {
        table.render({
            elem:"#table_id",
            data:data,
            limit:6,
            toolbar:'#toolbarDemo',
            page:true,
            cols:[[
                {type:'checkbox',align:'center',width:40},
                {title:'序号',width:60,align:'center',templet:function(data){
                        return data.LAY_INDEX;
                    }},
                {field:'article_url',title:'文章图片',align:'center',width:130,templet:function(data){
                        return "<img src='"+data.article_url+"'height='100'>";
                    }},
                {field:'article_title',title:'文章标题',align:'center'},
                {field:'acticle_categray_name',title:'分类',align:'center'},
                {field:'collection_num',title:'收藏量',align:'center'},
                {field:'article_like',title:'点赞量',align:'center'},
            ]]
        });
    }


});

